#include "InspectorAgent.h"
#include "Enums.h"
#include "Kit.h"
#include "TableInterface.h"

using namespace std;

InspectorAgent::InspectorAgent(string name) : Agent(name) {
	inspectionScheduled = false;
}

InspectorAgent::~InspectorAgent() {
	// Nothing to delete?
}

void InspectorAgent::msgInspectKit() {
	qDebug() << "msgInspectKit";
	inspectionScheduled = true;
	stateChanged();
}

bool InspectorAgent::pickAndExecuteAnAction() {
	if(inspectionScheduled) {
		inspectKitOnTable();
		return true;
	}

	return false;
}

void InspectorAgent::inspectKitOnTable() {
	inspectionScheduled = false;

	gui->takePicture();

	sleep(1);

	Kit* kit = this->table->peek(2);

	InspectorKitState kitState;

	if(kit == NULL) {
		kitState = None;
	} else if(kit->isComplete()) {
		kitState = Good;
	} else {
		kitState = Bad;
	}

	kitRobot->msgHereIsKitState(kitState);

	stateChanged();
}